package cn.wolfcode.controller;

import cn.wolfcode.domain.BalanceDetail;
import cn.wolfcode.domain.UserWallet;
import cn.wolfcode.service.IUserWalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@Slf4j
@RestController("/userWallet")
public class UserWalletController {

    @Autowired
    private IUserWalletService userWalletService;

    @GetMapping("/byUserId")
    public String byUserId(Long userId) {

        // 1: 判断用户是否登录以及是否为当前登录用户

        // 2: 根据用户ID去查询得到钱包
        UserWallet userWallet = userWalletService.byUserId(userId);
        log.info("[查询钱包通过用户ID] userId:{}, rest:{}", userId, userWallet);

        return "查询用户钱包余额";
    }

    @PostMapping("/pay")
    public String pay(Long userId, BigDecimal payMoney, String info) {

        // 1: 判断用户是否登录以及是否为当前登录用户

        // 2: 用户支付
        boolean rest = userWalletService.pay(userId, payMoney, info);
        log.info("[用户支付] userId:{}, rest:{}", userId, rest);

        return "用户消费100元的接口";
    }

    @PostMapping("/refund")
    public String refund(Long detailId, String refundInfo) {

        // 1: 判断用户是否登录以及是否为当前登录用户

        // 2: 用户退款
        boolean rest = userWalletService.refund(detailId, refundInfo);
        log.info("[退款] detailId:{}, rest:{}", detailId, rest);

        return "用户退款接口";
    }
}
